﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ToolUtity;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using DevExpress.XtraRichEdit;
using DevExpress.Utils;
using DevExpress.XtraBars;
using DevExpress.XtraRichEdit.API.Native;
using wd = Microsoft.Office.Interop.Word;
using System.Runtime.InteropServices;

namespace AHCS
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
        uint KEYEVENTF_KEYUP = 0x0002;

        object missing = Type.Missing;
        //安徽长升信息技术有限公司
        const string temqls = "temqls.rft";
        public string QQ493551998 = "QQ493551998";
        LoadingWindow ladwin = new LoadingWindow();

        public Form1()
        {
            InitializeComponent();
        }
          

        /// <summary>
        /// 当前面板的大和小的宽度，还有容器宽高
        /// </summary>
        int maxwidht, maxHeight, minph, minpw, mainp2w, mainp2h;
        Panel currentPane = null;
        RichEditControl curentRch = null;

        Dictionary<string, byte> keycodedic;
        private void Form1_Load(object sender, EventArgs e)
        {
            keycodedic = new Dictionary<string, byte>();
            Addkey();
            //KeyboardHook k_hook = new KeyboardHook();
            //k_hook.KeyUpEvent += new KeyEventHandler(hook_KeyUp);//钩住键放松
            //k_hook.Start();//安装键盘钩子


            maxwidht = panel1.Width;
            maxHeight = panel1.Height;
            minph = panel2.Height;
            minpw = panel2.Width;
            mainp2w = splitMainDif.Panel2.Width;
            mainp2h = splitMainDif.Panel2.Height;
            currentPane = panel1;
            curentRch = rchSmszy;
          
            //获取所有字体
           // this.Text = "test";
            Common.BackColor = rchQlyq.BackColor; 
             this.Text = "安徽长升信息技术有限公司 (QQ:878163778;微信：19810985732)";
             ladwin.StartPosition = FormStartPosition.CenterParent;
            // ISKeyong();
        
            //加载
            OpenMb(0);
            AutoCorrectOptions correctionOptions = rchZyft.Options.AutoCorrect;

            correctionOptions.CorrectTwoInitialCapitals = true;
            correctionOptions.DetectUrls = false;
            correctionOptions.ReplaceTextAsYouType = true;
            correctionOptions.UseSpellCheckerSuggestions = true;
        
        }

        





        #region 显示界面



        private void button1_Click(object sender, EventArgs e)
        {
            ShowView(panel1, rchSmszy);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ShowView(panel2, rchZyft);
            if (opzyft == 1)
            {
                rchZyft.Focus();
             
                    Thread.Sleep(100);
                    SendKeys.Send("^{END}");
                    SendKeys.Send("{BACKSPACE}");
             
                opzyft = 0;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ShowView(panel3, rchQlyq);

            if (opqlyq == 1)
            {
                rchQlyq.Focus();
                    Thread.Sleep(100);
                    SendKeys.Send("^{END}");
                    SendKeys.Send("{BACKSPACE}");
                opqlyq = 0;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            ShowView(panel4, rchSms);

            if (opsms == 1)
            {
                rchSms.Focus();
           
                    SendKeys.Send("^{END}");
                    SendKeys.Send("{BACKSPACE}");
            
                opsms = 0;
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {

            ShowView(panel5, rchSmsft);
        }

        int foirWind = 270;// 三个固定窗口
     
        public void ShowView(Panel pcuretn, RichEditControl rch)
        {
            if (barbtnFenFu.Caption == "已分幅")
            {
                if (pcuretn == currentPane)
                {
                    return;
                }

                foreach (object item in splitMainDif.Panel2.Controls)
                {
                    if (item is Panel)
                    {
                        Panel temp = item as Panel;
                        if (temp != pcuretn || temp != currentPane)
                        {
                            temp.Height = minph;
                            temp.Width = 70;
                        }
                    }
                }

                // int cwidth = (maxwidht + (splitMain.Panel2.Width - mainp2w)) / 2;
                int cwidth = (splitMainDif.Panel2.Width - 200) / 2;
                currentPane.Width = cwidth;
                pcuretn.Width = cwidth;
                currentPane = pcuretn;

            }
            else
            {
                foreach (object item in splitMainDif.Panel2.Controls)
                {
                    if (item is Panel)
                    {
                        Panel temp = item as Panel;
                        if (temp != pcuretn)
                        {
                            temp.Height = minph;
                            temp.Width = minpw;
                        }
                        else
                        {
                            temp.Height = maxHeight + (splitMainDif.Panel2.Height - mainp2h);
                            //  temp.Width = maxwidht + (splitMain.Panel2.Width - mainp2w);
                            temp.Width = splitMainDif.Panel2.Width - foirWind;
                            currentPane = pcuretn;
                            foreach (var itemrch in currentPane.Controls)
                            {
                                if (itemrch is RichEditControl)
                                {
                                    curentRch = itemrch as RichEditControl; //设置当前RichTextBox
                                }
                            }
                        }

                    }
                }
            }
            richEditBarController1.Control = rch;

            

        }

        // 统计字数
        private void rchQlyq_TextChanged(object sender, EventArgs e)
        {
            tsqlyqcount.Text = rchQlyq.Text.Length.ToString();
        }

        private void rchSms_TextChanged(object sender, EventArgs e)
        {
            tssmscount.Text = rchSms.Text.Length.ToString();
        }



        #endregion


        #region 1打开保存模板

        /// <summary>
        /// 1,实用模板，2发明模板
        /// </summary>
        int mbtype = 0;
        private void tsNewShiYong_Click(object sender, EventArgs e)
        {

            OpenMb(1);
        }

        private void tsNewFaMin_Click(object sender, EventArgs e)
        {

            OpenMb(2);
        }

        //保存实用模板
        private void tsSaveShiYon_Click(object sender, EventArgs e)
        {
            SaveMb(1);
        }

        //新建发明模板
        private void tsSaveFM_Click(object sender, EventArgs e)
        {
            SaveMb(2);
        }

        private void SaveMb(int type)
        {
            string curedir = Path.Combine(Environment.CurrentDirectory, "MoBan");
            if (!Directory.Exists(curedir))
            {
                Directory.CreateDirectory(curedir);
            }

            rchSmszy.SaveDocument($"{curedir}\\{type}smszy.doc", DocumentFormat.Doc);
            rchQlyq.SaveDocument($"{curedir}\\{type}qlyqs.doc", DocumentFormat.Doc);
            rchZyft.SaveDocument($"{curedir}\\{type}zyft.doc", DocumentFormat.Doc);
            rchSms.SaveDocument($"{curedir}\\{type}sms.doc", DocumentFormat.Doc);
            rchSmsft.SaveDocument($"{curedir}\\{type}smsft.doc", DocumentFormat.Doc);

            MessageBox.Show("保存模板成功");
        }

        /// <summary>
        /// 打开模板
        /// </summary>
        /// <param name="type"></param>
        private void OpenMb(int type)
        {
            mbtype = type;
            string mbdir = Path.Combine(Environment.CurrentDirectory, "MoBan");
            if (!File.Exists($"{mbdir}\\{type}smszy.doc"))
            {
                return;
            }
            string f1 = Path.Combine(Environment.CurrentDirectory + "\\tem", "smszy.doc");
            string f2 = Path.Combine(Environment.CurrentDirectory + "\\tem", "zyft.doc");
            string f3 = Path.Combine(Environment.CurrentDirectory + "\\tem", "qlyqs.doc");
            string f4 = Path.Combine(Environment.CurrentDirectory + "\\tem", "sms.doc");
            string f5 = Path.Combine(Environment.CurrentDirectory + "\\tem", "smsft.doc");
            File.Copy($"{mbdir}\\{type}smszy.doc", f1, true);
            File.Copy($"{mbdir}\\{type}zyft.doc", f2, true);
            File.Copy($"{mbdir}\\{type}qlyqs.doc", f3, true);
            File.Copy($"{mbdir}\\{type}sms.doc", f4, true);
            File.Copy($"{mbdir}\\{type}smsft.doc", f5, true);
            rchSmszy.LoadDocument(f1, DocumentFormat.Doc);
            rchZyft.LoadDocument(f2, DocumentFormat.Doc);
            rchQlyq.LoadDocument(f3, DocumentFormat.Doc);
            rchSms.LoadDocument(f4, DocumentFormat.Doc);
            rchSmsft.LoadDocument(f5, DocumentFormat.Doc);
            tslblfoot.Text = "";

        }


        #endregion




        #region 查找替换

        int bkzy = 0, bkzyft = 0, bksms = 0, bkqlyqf = 0, bksmsft = 0;
        /// <summary>
        /// 查找全部
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            bkzy = 1; bkzyft = 1; bksms = 1; bkqlyqf = 1; bksmsft = 1;
            ShowFindKey(rchSmszy, Color.Yellow);
            ShowFindKey(rchZyft, Color.Yellow);
            ShowFindKey(rchQlyq, Color.Yellow);
            ShowFindKey(rchSms, Color.Yellow);
            ShowFindKey(rchSmsft, Color.Yellow);
        }

        /// <summary>
        /// 替换全部
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barButtonItem2_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (txtfind.EditValue.ToString() != "")
            {
                if (bkzy == 1)
                {
                    ShowFindKey(rchSmszy, Common.BackColor);
                }
                if (bkzyft == 1)
                {
                    ShowFindKey(rchZyft, Common.BackColor);
                }
                if (bkqlyqf == 1)
                {
                    ShowFindKey(rchQlyq, Common.BackColor);
                }
                if (bksms == 1)
                {
                    ShowFindKey(rchSms, Common.BackColor);
                }
                if (bksmsft == 1)
                {
                    ShowFindKey(rchSmsft, Common.BackColor);
                }

                TiHuanAll(rchSmszy);
                TiHuanAll(rchZyft);
                TiHuanAll(rchQlyq);
                TiHuanAll(rchSms);
                TiHuanAll(rchSmsft);
            }
        }






        /// <summary>
        /// 替换全部
        /// </summary>
        /// <param name="rch"></param>
        private void TiHuanAll(RichEditControl rch)
        {
            Document document = rch.Document;
            document.BeginUpdate();
            document.SelectAll();
            document.ReplaceAll(txtfind.EditValue.ToString(), txtContentAfter.EditValue.ToString(), SearchOptions.None);
            document.EndUpdate();
        }



        /// <summary>
        /// 查找
        /// </summary>
        /// <param name="re"></param>
        /// <param name="strList"></param>
        private void ShowFindKey(RichEditControl re, Color cr)
        {
            DocumentRange[] list = re.Document.FindAll(new System.Text.RegularExpressions.Regex(txtfind.EditValue.ToString()));

            for (int i = 0; i < list.Length; i++)
            {
                CharacterProperties cp = re.Document.BeginUpdateCharacters(list[i]);
                cp.BackColor = cr;
                re.Document.EndUpdateCharacters(cp);
            }
        }


        //清楚 背景
        private void rchQlyq_Click_1(object sender, EventArgs e)
        {
            if (Common.hasback == 1)
            {
                // 校验背景色
                var cp = rchQlyq.Document.BeginUpdateCharacters(0, rchQlyq.Text.Length);
                cp.BackColor = Common.BackColor;
                rchQlyq.Document.EndUpdateCharacters(cp);
                Common.hasback = 0;
            }
            // 搜索背景
            if (txtfind.EditValue.ToString().Length > 0 && bkqlyqf == 1)
            {
                bkqlyqf = 0;
                ShowFindKey(rchQlyq, Common.BackColor);
            }

        }

        private void rchSmszy_Click(object sender, EventArgs e)
        {
            if (txtfind.EditValue.ToString().Length > 0 && bkzy == 1)
            {
                bkzy = 0;
                ShowFindKey(rchSmszy, Common.BackColor);
            }
        }

        private void rchZyft_Click(object sender, EventArgs e)
        {
            if (txtfind.EditValue.ToString().Length > 0 && bkzyft == 1)
            {
                bkzyft = 0;
                ShowFindKey(rchZyft, Common.BackColor);
            }
        }

        private void rchSms_Click(object sender, EventArgs e)
        {
            if (txtfind.EditValue.ToString().Length > 0 && bksms == 1)
            {
                bksms = 0;
                ShowFindKey(rchSms, Common.BackColor);
            }

        }

        private void rchSmsft_Click(object sender, EventArgs e)
        {
            if (txtfind.EditValue.ToString().Length > 0 && bksmsft == 1)
            {
                bksmsft = 0;
                ShowFindKey(rchSmsft, Common.BackColor);
            }
        } 
        #endregion
         

        #region 校验和图例

       
      
        #endregion


        //注册
        private void btnReg_Click(object sender, EventArgs e)
        {
            RegForm rf = new RegForm();
            //  rf.syday = saveday;
            rf.ShowDialog();
        }
        
    
         

        string threg = @"[\d]+[、.]\w+，其特征在于：";
        //生成技术方案
        private void barbtnjsfa_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(rchQlyq.Text))
            {
                MessageBox.Show("权利要求书内容不能为空");
                return;
            }
            string res = Regex.Replace(rchQlyq.Text, threg, "优选地，");
            res = Regex.Replace(res, @"（[\d]+）", "");
            IDataObject iData = Clipboard.GetDataObject();
           
                Clipboard.SetDataObject(res);
            
        }

        //生成实施方案
        private void barbtnSs_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(rchQlyq.Text))
            {
                MessageBox.Show("权利要求书内容不能为空");
                return;
            }

            if (string.IsNullOrWhiteSpace(rchQlyq.Text))
            {
                return;
            }
            string res = Regex.Replace(rchQlyq.Text, threg, "如图1－3所示，");
            res = Regex.Replace(res, @"（[\d]+）", new MatchEvaluator(Common.CorrectString), RegexOptions.Compiled | RegexOptions.IgnoreCase);
            res = res.Replace("所述", "");
            Clipboard.SetText(res);
            IDataObject iData = Clipboard.GetDataObject();
            
                Clipboard.SetDataObject(res);
            

        }

        private void rchSmszy_TextChanged(object sender, EventArgs e)
        {
            tssmszyCount.Text = rchSmszy.Text.Length.ToString();
            if (rchSmszy.Text.Length >= 300)
            {
                tssmszyCount.Text = $"不能多于300个字当前{rchSmszy.Text.Length}";
            }
        }


        // 增加权要
        private void barbtnqy_ItemClick(object sender, ItemClickEventArgs e)
        {
            Regex rgx = new Regex(@"[\d].根据权利要求(.*)其特征在于：");
            if (rgx.IsMatch(rchQlyq.Text))
            {
                MatchCollection mc = rgx.Matches(rchQlyq.Text);
                string str = mc[mc.Count - 1].Value;
                string resstr = Common.StrNumAdd(str);
                rchQlyq.Document.InsertText(rchQlyq.Document.Range.End, "\r\n" + resstr);

            }
            else
            {
                MessageBox.Show("模板数据不对");
            }
        }

        //保存整本
        private void barButtonItem4_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tslblfoot.Text == "")
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title = "请选择要保存的⽂件路径";

                sfd.InitialDirectory = Application.StartupPath;
                //todo:
                // sfd.Filter = "文档⽂件|*.doc|PDF⽂件|*.pdf|所有⽂件|*.*";
                sfd.Filter = "文档⽂件|*.doc";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                   
                    SaveAll(sfd.FileName);
                }

            }
            else
            {

                File.Delete(tslblfoot.Text);
                SaveAll(tslblfoot.Text);
            }
        }



        //另存为整本
        private void barbtnSaveas_ItemClick(object sender, ItemClickEventArgs e)
        {


            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Title = "请选择要保存的⽂件路径";

            sfd.InitialDirectory = Application.StartupPath;
            //todo:
            // sfd.Filter = "文档⽂件|*.doc|PDF⽂件|*.pdf|所有⽂件|*.*";
            sfd.Filter = "文档⽂件|*.doc|PDF⽂件|*.pdf";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                string hz = Path.GetExtension(sfd.FileName);
                string fname = Path.GetFileNameWithoutExtension(sfd.FileName);
                
                if (hz.ToLower() == ".pdf")
                {
                    string savename = tslblfoot.Text;
                    string temdir = Environment.CurrentDirectory + "\\tem\\lincun.doc";
                    SaveAll(temdir);
                    Common.ASPOSEWordToPDF(temdir, sfd.FileName);
                     tslblfoot.Text= savename;
                }
                else
                {
                    SaveAll(sfd.FileName);

                }
                  

            }




        }



        int opzyft=0, opqlyq=0, opsms=0;
        // 打开整本
        private void barOpenBen_ItemClick(object sender, ItemClickEventArgs e)
        {
            rchSmszy.Document.Delete(rchSmszy.Document.Range);
            rchZyft.Document.Delete(rchZyft.Document.Range);
            rchQlyq.Document.Delete(rchQlyq.Document.Range);
            rchSms.Document.Delete(rchSms.Document.Range);
            rchSmsft.Document.Delete(rchSmsft.Document.Range);

            Opendoc();
            opzyft = 1; opqlyq = 1; opsms = 1;
            rchSmszy.Focus();
              Thread.Sleep(100);
              SendKeys.Send("^{END}");
              SendKeys.Send("{BACKSPACE}");
            

            //rchZyft.Focus();
            //SendKeys.Send("^{END}");
            //SendKeys.Send("{LEFT}");
            //SendKeys.Send("{BACKSPACE}");
            //  rchSmszy.Document.Delete(rchSmszy.Document.Paragraphs.Last().Range);

            

        }

        //打开整本
        private void Opendoc()
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "Word 2003文件|*.doc";
            DialogResult result = dialog.ShowDialog();
            if (result == DialogResult.OK)
            {

                tslblfoot.Text = dialog.FileName;
            }
            else
            {
                return;
            }

            rchSmszy.ResetText();
            rchZyft.ResetText();
            rchSms.ResetText();
            rchQlyq.ResetText();
            rchSmsft.ResetText();
            OpenLoad();

            object docFileName = tslblfoot.Text;

            // object docFileName = @"D:\开发常用工具\文档处理\一种定量挤牙膏工具.doc";
            wd.Application app = new Microsoft.Office.Interop.Word.Application();
            wd.Document doc = null;
            try
            {
                object visbl = false;
                object unknow = Type.Missing;
                app.Visible = false;
                //打开Word文件  
                doc = app.Documents.Open(ref docFileName, ref missing);
                app.Visible = false;
                object objWhat = wd.WdGoToItem.wdGoToPage;  // WdGoToItem 枚举    项目类型
                object objWhich = wd.WdGoToDirection.wdGoToNext;    //   位置
                                   
                // 总页数
                int filePages = doc.ComputeStatistics(wd.WdStatistic.wdStatisticPages, ref missing);
                
            object page = null;  // 页号
                page = 1;

                object lastpos = 0;
                Wordxq smszywd = new Wordxq();
                Wordxq zyftwd = new Wordxq();
                Wordxq smswd = new Wordxq();
                Wordxq qlyqswd = new Wordxq();
                Wordxq smsftwd = new Wordxq();
                for (int i = 1; i <= doc.Paragraphs.Count; i++)
                {
                    page = i;
               
                    wd.Range xq1 = doc.Paragraphs[i].Range;

                    string alltext = xq1.Text;
                    string headers = "";
                    foreach (wd.Section item in xq1.Sections)
                    {
                        foreach (wd.HeaderFooter aHeader in item.Headers)
                        {
                            if (!string.IsNullOrWhiteSpace(aHeader.Range.Text))
                            {
                                headers = aHeader.Range.Text.Trim();
                            }
                        }
                      
                    }
                    if (headers == "说明书摘要")
                    {
                        if (smszywd.Start == null)
                        {
                            smszywd.Start = 0;
                        }
                        smszywd.End = xq1.End;
                    }
                    else if (headers == "摘要附图")
                    {
                        if (zyftwd.Start == null)
                        {
                            zyftwd.Start = xq1.Start;
                        }
                        zyftwd.End = xq1.End;
                    }
                    else if (headers == "权利要求书")
                    {
                        if (qlyqswd.Start == null)
                        {
                            qlyqswd.Start = xq1.Start;
                        }
                        qlyqswd.End = xq1.End;
                    }
                    else if (headers == "说明书")
                    {
                        if (smswd.Start == null)
                        {
                            smswd.Start = xq1.Start;
                        }
                        smswd.End = xq1.End;
                    }
                    else if (headers == "说明书附图")
                    {
                        if (smsftwd.Start == null)
                        {
                            smsftwd.Start = xq1.Start;
                        }
                        smsftwd.End = xq1.End;
                    }


                }



                string f1 = Path.Combine(Environment.CurrentDirectory + "\\tem", "tsmszy.rtf");
                string f2 = Path.Combine(Environment.CurrentDirectory + "\\tem", "tzyft.rtf");
                string f3 = Path.Combine(Environment.CurrentDirectory + "\\tem", "tqlyqs.rtf");
                string f4 = Path.Combine(Environment.CurrentDirectory + "\\tem", "tsms.rtf");
                string f5 = Path.Combine(Environment.CurrentDirectory + "\\tem", "tsmsft.rtf");

                FileUtil.DeleteFile(f1);
                FileUtil.DeleteFile(f2);
                FileUtil.DeleteFile(f3);
                FileUtil.DeleteFile(f4);
                FileUtil.DeleteFile(f5);
                ;

                object format = wd.WdSaveFormat.wdFormatRTF;
                object b1 = smszywd.Start;
                object b2 = smszywd.End;
                wd.Range xq2 = doc.Range(ref b1, ref b2);

                //xq2.Find.ClearFormatting();
                //xq2.Find.Replacement.ClearFormatting();
                //xq2.Find.Text = "^m";
                //xq2.Find.Replacement.Text = "";

                //object replace = wd.WdReplace.wdReplaceAll;
                //xq2.Find.Execute(
                //    ref missing, ref missing, ref missing, ref missing,
                //    ref missing, ref missing, ref missing, ref missing,
                //    ref missing, ref missing, ref replace, ref missing,
                //    ref missing, ref missing, ref missing);
                
                xq2.Select();
                xq2.Copy();
                 rchSmszy.Paste();

                wd.Document destDoc = new wd.Document();
                destDoc.Content.Paste();
                destDoc.Sections[1].Range.Paste();
                object f1o = f1;
                ////改变文档类型
               // wd.Paragraphs ps = destDoc.Paragraphs;
               //int ix= ps[destDoc.Paragraphs.Count - 1].Range.Delete();
               
                destDoc.SaveAs(ref f1o, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                destDoc.Close();
                rchSmszy.LoadDocument(f1, DocumentFormat.Rtf);

                b1 = zyftwd.Start;
                b2 = zyftwd.End;
                xq2 = doc.Range(ref b1, ref b2);
                xq2.Select();
                xq2.Copy();
                rchZyft.Paste();
                wd.Document destDoc2 = new wd.Document();
                destDoc2.Sections[1].Range.Paste();
                object f20 = f2;
                destDoc2.SaveAs(ref f20, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                destDoc2.Close();
                rchZyft.LoadDocument(f2, DocumentFormat.Rtf);



                b1 = qlyqswd.Start;
                b2 = qlyqswd.End;
                xq2 = doc.Range(ref b1, ref b2);
                xq2.Select();
                xq2.Copy();
                //rchQlyq.Paste();
                wd.Document destDoc3 = new wd.Document();
                destDoc3.Sections[1].Range.Paste();
                object f30 = f3;
                destDoc3.SaveAs(ref f30, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                destDoc3.Close();
                rchQlyq.LoadDocument(f3, DocumentFormat.Rtf);



                b1 = smswd.Start;
                b2 = smswd.End;
                xq2 = doc.Range(ref b1, ref b2);
                xq2.Select();
                xq2.Copy();
                // rchSms.Paste();
                wd.Document destDoc4 = new wd.Document();
                destDoc4.Sections[1].Range.Paste();
                object f40 = f4;
                destDoc4.SaveAs(ref f40, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                destDoc4.Close();
                rchSms.LoadDocument(f4, DocumentFormat.Rtf);



                b1 = smsftwd.Start;
                b2 = smsftwd.End;
                xq2 = doc.Range(ref b1, ref b2);
                xq2.Select();
                xq2.Copy();
                //rchSmsft.Paste();
                wd.Document destDoc5 = new wd.Document();
                destDoc5.Sections[1].Range.Paste();
                object f50 = f5;
                destDoc5.SaveAs(ref f50, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                destDoc5.Close();
                rchSmsft.LoadDocument(f5, DocumentFormat.Rtf);

                CloseLoad();

                //记录选取位置 

                //   doc.Save();
            }
            catch (Exception ce)
            {
                MessageBox.Show("发生错误" + ce.Message);
                //Common.WriteLog(ce.StackTrace);
            }
            finally
            {
                doc.Close();
                app.Quit(missing, missing, missing);
                CloseLoad();
            }

        }

      

        #region 空格键

        private void rchSmszy_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == ' ')//Char.IsNumber()方法用于表示指定的Unicode字符是否被归类为数字。
            {                                              //'b'是退格键

                rchSmszy.Document.InsertText(rchSmszy.Document.CaretPosition, "　");
                e.Handled = true;
            }
            else if (e.KeyChar == '-' || e.KeyChar == '-')//Char.IsNumber()方法用于表示指定的Unicode字符是否被归类为数字。
            {                                              //'b'是退格键

                rchSmszy.Document.InsertText(rchSmszy.Document.CaretPosition, "－");
                e.Handled = true;
            }
         
            tssmszyCount.Text = rchSmszy.Text.Length.ToString();
            if (rchSmszy.Text.Length > 300)
            {
                e.Handled = true;
            }
          
            
        }

     
 
        bool isdown = false;
        /// <summary>
        /// 在keyup中自动输入括号
        /// </summary>
        /// <param name="e"></param>
        /// <param name="rch"></param>
        private void AutoKH(KeyEventArgs e,RichEditControl rch)
        {
            if (e.Shift)
            {
                int kjj = (int)Control.ModifierKeys; //(int)Keys.Shift 
                if (e.KeyValue == (int)Keys.D9 && (kjj == 65536))
                {
                    isdown = true;
                    int sta = rch.Document.CaretPosition.ToInt();
                    if (sta > 1)
                    {
                        sta -= 1;
                    }
                    DocumentRange formattedRange = rch.Document.CreateRange(sta, 1);
                    SubDocument sdoc = formattedRange.BeginUpdateDocument();
                    string str = sdoc.GetText(formattedRange);
                    if (str == "（")
                    {
                        sdoc.InsertText(rch.Document.CaretPosition, "）");

                    }
                    else if (str == "(")
                    {
                        sdoc.InsertText(rch.Document.CaretPosition, ")"); //英文
                    }
                    formattedRange.EndUpdateDocument(sdoc);

                }
                else if (e.KeyValue == (int)Keys.OemOpenBrackets && (kjj == 65536))
                {
                    isdown = true;
                    int sta = rch.Document.CaretPosition.ToInt();
                    if (sta > 1)
                    {
                        sta -= 1;
                    }
                    DocumentRange formattedRange = rch.Document.CreateRange(sta, 1);
                    SubDocument sdoc = formattedRange.BeginUpdateDocument();
                    string str = sdoc.GetText(formattedRange);
                    if (str == "{")
                    {
                        sdoc.InsertText(rch.Document.CaretPosition, "}");

                    }
                    formattedRange.EndUpdateDocument(sdoc);
                    //isdown = true;
                    //keybd_event(0x1, 0, 1, 0);
                    //keybd_event(keycodedic["SHIFT"], 0, 1, 0);
                    //keybd_event(keycodedic["]"], 0, 1, 0);
                    //Thread.Sleep(50);
                    //keybd_event(keycodedic["]"], 0, KEYEVENTF_KEYUP, 0);
                    //Thread.Sleep(50);
                }
                else if (e.KeyValue == 222 && (kjj == 65536))
                {
                    //双引号

                    int sta = rch.Document.CaretPosition.ToInt();
                    if (sta > 1)
                    {
                        sta -= 1;
                    }
                    DocumentRange formattedRange = rch.Document.CreateRange(sta, 1);
                    SubDocument sdoc = formattedRange.BeginUpdateDocument();
                    string str = sdoc.GetText(formattedRange);
                    if (str == "“")
                    {
                        isdown = true;
                        sdoc.InsertText(rch.Document.CaretPosition, "”");
                    }
                    formattedRange.EndUpdateDocument(sdoc);

                }

            }
            else
            {
                if (e.KeyValue == (int)Keys.OemOpenBrackets)
                {
                    isdown = true;
                    Thread.Sleep(50);
                    keybd_event(0x1, 0, 1, 0);
                    keybd_event(keycodedic["]"], 0, 1, 0);
                    Thread.Sleep(50);
                    keybd_event(keycodedic["]"], 0, KEYEVENTF_KEYUP, 0);
                    Thread.Sleep(50);
                }

            }

            if (isdown && e.KeyValue == (int)Keys.ShiftKey)
            {
                isdown = false;
                Task.Run(() =>
                {
                    Thread.Sleep(50);
                    //keybd_event(keycodedic["SHIFT"], 0, KEYEVENTF_KEYUP, 0);
                    //keybd_event(0x1, 0, 1, 0);
                    //Thread.Sleep(200);
                    keybd_event(keycodedic["LEFT"], 0, 1, 0);
                    Thread.Sleep(50);
                    keybd_event(keycodedic["LEFT"], 0, KEYEVENTF_KEYUP, 0);


                });

            }
        }


        private void rchZyft_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == ' ')//Char.IsNumber()方法用于表示指定的Unicode字符是否被归类为数字。
            {                                              //'b'是退格键

                rchZyft.Document.InsertText(rchZyft.Document.CaretPosition, "　");
                e.Handled = true;
            }
            else if (e.KeyChar == '-' || e.KeyChar == '-')//Char.IsNumber()方法用于表示指定的Unicode字符是否被归类为数字。
            {                                              //'b'是退格键

                rchZyft.Document.InsertText(rchZyft.Document.CaretPosition, "－");
                e.Handled = true;
            }

            //if (e.KeyChar == '(')
            //{                                              //'b'是退格键

            //    rchZyft.Document.InsertText(rchZyft.Document.CaretPosition, "()");
            //    e.Handled = true;
            //}


        }

        private void rchQlyq_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == ' ')//Char.IsNumber()方法用于表示指定的Unicode字符是否被归类为数字。
            {                                              //'b'是退格键

                rchQlyq.Document.InsertText(rchQlyq.Document.CaretPosition, "　");
                e.Handled = true;
            }
            else if (e.KeyChar == '-' || e.KeyChar == '-')//Char.IsNumber()方法用于表示指定的Unicode字符是否被归类为数字。
            {                                              //'b'是退格键

                rchQlyq.Document.InsertText(rchQlyq.Document.CaretPosition, "－");
                e.Handled = true;
            }
        }

       

        private void splitMainDif_Panel2_SizeChanged(object sender, EventArgs e)
        {
            if (currentPane == null || splitMainDif == null || splitMainDif.Panel2 == null)
            {
                return;
            }
            maxwidht = panel1.Width;
            maxHeight = panel1.Height;
            // currentPane.Width = maxwidht + (splitMain.Panel2.Width - mainp2w);

            if (barbtnFenFu.Caption == "已分幅")
            {
                currentPane.Width = (splitMainDif.Panel2.Width - 200) / 2;
            }
            else
            {
                currentPane.Width = splitMainDif.Panel2.Width - foirWind;
            }
            currentPane.Height = maxHeight + (splitMainDif.Panel2.Height - mainp2h);

        }

        private void rchSms_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == ' ')//Char.IsNumber()方法用于表示指定的Unicode字符是否被归类为数字。
            {                                              //'b'是退格键

                rchSms.Document.InsertText(rchSms.Document.CaretPosition, "　");
                e.Handled = true;
            }
            else if (e.KeyChar == '-' || e.KeyChar == '-')//Char.IsNumber()方法用于表示指定的Unicode字符是否被归类为数字。
            {                                              //'b'是退格键

                rchSms.Document.InsertText(rchSms.Document.CaretPosition, "－");
                e.Handled = true;
            }
        }

        private void rchSmsft_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == ' ')//Char.IsNumber()方法用于表示指定的Unicode字符是否被归类为数字。
            {                                              //'b'是退格键

                rchSmsft.Document.InsertText(rchSmsft.Document.CaretPosition, "　");
                e.Handled = true;
            }
            else if (e.KeyChar == '-' || e.KeyChar == '-')//Char.IsNumber()方法用于表示指定的Unicode字符是否被归类为数字。
            {                                              //'b'是退格键

                rchSmsft.Document.InsertText(rchSmsft.Document.CaretPosition, "－");
                e.Handled = true;
            }
        }

        // 自动补全
        private void rchSmszy_KeyUp(object sender, KeyEventArgs e)
        {
            AutoKH(e, rchSmszy);
        }
        
        private void rchZyft_KeyUp(object sender, KeyEventArgs e)
        {
            AutoKH(e, rchZyft);
        }

        private void rchQlyq_KeyUp(object sender, KeyEventArgs e)
        {
            AutoKH(e, rchQlyq);
        }

        private void rchSms_KeyUp(object sender, KeyEventArgs e)
        {
            AutoKH(e, rchSms);
        }

        private void rchSmsft_KeyUp(object sender, KeyEventArgs e)
        {
            AutoKH(e, rchSmsft);
        }

     
        #endregion


        JiaoYanWinow jywindwo = null;
        //弹出图例
        private void barButtonItem4_ItemClick_2(object sender, ItemClickEventArgs e)
        {
            if (jywindwo != null && jywindwo.IsDisposed == false)
            {

                jywindwo.Activate();
            }
            else
            {
                jywindwo = new JiaoYanWinow();
                jywindwo.rchQlyq = rchQlyq;
                jywindwo.Show();
            }
        }


        //单个保存
        private void barButtonItem3_ItemClick(object sender, ItemClickEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Title = "请选择要保存的⽂件路径";
            sfd.InitialDirectory = Application.StartupPath;
            sfd.Filter = "文档⽂件|*.doc|PDF⽂件|*.pdf";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                string hz = Path.GetExtension(sfd.FileName);
                string fname = Path.GetFileNameWithoutExtension(sfd.FileName);
                if (hz.ToLower() == ".pdf")
                {
                    // curentRch.ExportToPdf(sfd.FileName);
                    string f1 = Path.Combine(Environment.CurrentDirectory + "\\tem", "temsave.doc");
                    SaveDoc(curentRch, f1);
                    Common.ASPOSEWordToPDF(f1,sfd.FileName);
                  
                }
                else
                {
                    //curentRch.SaveDocument(sfd.FileName, DocumentFormat.Doc);
                    SaveDoc(curentRch,sfd.FileName);
                }
            }

        }

        /// <summary>
        /// aspoe保存为doc文件
        /// </summary>
        /// <param name="trch">富文本</param>
        /// <param name="filesrc">要保存的路径</param>
        private void SaveDoc(RichEditControl trch ,string filesrc)
        {

          //  rchSmszy.SelectAll();
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            byte[] dataBytes = encoding.GetBytes(trch.RtfText);
            MemoryStream stream = new MemoryStream(dataBytes);
            Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();
            loadOptions.LoadFormat = Aspose.Words.LoadFormat.Rtf;
            Aspose.Words.Document doc = new Aspose.Words.Document(stream, loadOptions);
            doc.Save(filesrc);
        }
        

        /// <summary>
        /// 全部保存
        /// </summary>
        /// <param name="filesrc"></param>
        private void SaveAll(string filesrc)
        {
            string dir = Path.GetDirectoryName(filesrc);
            
            string temdir = Environment.CurrentDirectory + "\\tem";
            string f1 = Path.Combine(temdir, "temsmszy.doc");
            string f2 = Path.Combine(temdir, "temzyft.doc");
            string f3 = Path.Combine(temdir, "temqlyqs.doc");
            string f4 = Path.Combine(temdir, "temsms.doc");
            string f5 = Path.Combine(temdir, "temsmsft.doc");

            //FileUtil.DeleteFile(f1);
            //FileUtil.DeleteFile(f2);
            //FileUtil.DeleteFile(f3);
            //FileUtil.DeleteFile(f4);
            //FileUtil.DeleteFile(f5);

            SaveDoc(rchSmszy, f1);
            SaveDoc(rchZyft, f2);
            SaveDoc(rchQlyq, f3);
            SaveDoc(rchSms, f4);
            SaveDoc(rchSmsft, f5);
            AsposeHelper.Combiedoc(f1, f2, f3, f4, f5, filesrc);
            tslblfoot.Text = filesrc;
        }



        private void barbtnFenFu_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (barbtnFenFu.Caption == "分幅")
            {
                barbtnFenFu.Caption = "已分幅";
            }
            else
            {
                barbtnFenFu.Caption = "分幅";
            }
        }

        /// <summary>
        /// 最新导出5书
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnExport5Book_ItemClick(object sender, ItemClickEventArgs e)
        {

            Ookii.Dialogs.VistaFolderBrowserDialog folderBrowser = new Ookii.Dialogs.VistaFolderBrowserDialog();

            folderBrowser.Description = "请选择五书导出目录";
            if (folderBrowser.ShowDialog() == DialogResult.OK)
            {
                string dir = folderBrowser.SelectedPath;
                string f1 = Path.Combine(dir, "说明书摘要.doc");
                string f2 = Path.Combine(dir, "摘要附图.pdf");
                string f3 = Path.Combine(dir, "权利要求书.doc");
                string f4 = Path.Combine(dir, "说明书.doc");
                string f5 = Path.Combine(dir, "说明书附图.pdf");
                //rchSmszy.SaveDocument(f1, DocumentFormat.Doc);
                //rchQlyq.SaveDocument(f3, DocumentFormat.Doc);
                //rchSms.SaveDocument(f4, DocumentFormat.Doc);
                //rchZyft.ExportToPdf(f2);
                //rchSmsft.ExportToPdf(f5);


                SaveDoc(rchSmszy, f1);
                SaveDoc(rchQlyq, f3);
                SaveDoc(rchSms, f4);

                string dc2 = Path.Combine(Environment.CurrentDirectory + "\\tem", "5srchZyft.doc");
                string dc5 = Path.Combine(Environment.CurrentDirectory + "\\tem", "5srchSmsft.doc");
                SaveDoc(rchZyft, dc2);
                SaveDoc(rchSmsft, dc5); 
         
                Common.ASPOSEWordToPDF(dc2, f2);
                Common.ASPOSEWordToPDF( dc5, f5);

            }
        }




        /// <summary>
        /// 打开加载框
        /// </summary>
        public void OpenLoad()
        {
          
            //this.Hide();
            Task.Run(() =>
            {
                ladwin.ShowDialog();
            });


        }


        /// <summary>
        /// guanbi 
        /// </summary>
        public void CloseLoad()
        {
            Invoke(new Action(() =>
            {
                ladwin.Hide();
            }));
            this.Show();
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            if (Common.ISkeyong() == false)
            {
                timer1.Enabled = false;
                MessageBox.Show("软件已过使用期，请联系公司购买");
                Environment.Exit(0);
            }

            if (Common.hasNetWork==false)
            {
                string mulit = TimeClass.ReadSetting("runMcount", "1");
                int fenzhong = mulit.ToInt32()+1;
                int tishi = 1440 - fenzhong;
                if (fenzhong > 1437)//1440
                {
                    MessageBox.Show($"请在24小时内联网，{tishi} 分钟后即将退出,请注意保存内容");
                }
                if (fenzhong > 1440)//1401
                {
                    Environment.Exit(0); 
                }
                 
                TimeClass.WriteSetting("runMcount", fenzhong.ToString());//     清空计时器
            }


        }

       
        private void hook_KeyUp(object sender, KeyEventArgs e)
        {
            //int kjj = (int)Control.ModifierKeys; //(int)Keys.Shift 
            //if (e.KeyValue == (int)Keys.D9 && (kjj == 65536))
            //{
                 
            //    Thread.Sleep(50);
            //    keybd_event(0x1, 0, 1, 0);
            //    keybd_event(keycodedic["SHIFT"], 0, 1, 0);
            //    keybd_event(keycodedic["0"], 0, 1, 0);
            //    Thread.Sleep(50);
            //    keybd_event(keycodedic["0"], 0, KEYEVENTF_KEYUP, 0);
            //    Thread.Sleep(50);
            //    // keybd_event(keycodedic["SHIFT"], 0, KEYEVENTF_KEYUP, 0);
            //    Thread.Sleep(50);
            //    isdown = true;
            //}
            //else if (e.KeyValue == (int)Keys.OemOpenBrackets && (kjj == 65536))
            //{ 
            //    Thread.Sleep(50);
            //    keybd_event(0x1, 0, 1, 0);
            //    keybd_event(keycodedic["SHIFT"], 0, 1, 0);
            //    keybd_event(keycodedic["]"], 0, 1, 0);
            //    Thread.Sleep(50);
            //    keybd_event(keycodedic["]"], 0, KEYEVENTF_KEYUP, 0);
            //    Thread.Sleep(50); 
            //    Thread.Sleep(50);
            //    isdown = true;
            //}

            //else if (isdown && (e.KeyValue == 160 || e.KeyValue == 161))
            //{
            //    isdown = false; 
            //    Thread.Sleep(50);
            //    keybd_event(keycodedic["SHIFT"], 0, KEYEVENTF_KEYUP, 0);
            //    Task.Run(() =>
            //    {
            //        Thread.Sleep(100);
            //        keybd_event(keycodedic["LEFT"], 0, 1, 0);
            //        keybd_event(0x1, 0, 1, 0);
            //        keybd_event(keycodedic["LEFT"], 0, KEYEVENTF_KEYUP, 0);
            //    });
            //}
        }


        private void Addkey()
        {
            keycodedic.Add("backspace", 0x08);
            keycodedic.Add("tab", 0x09);
            keycodedic.Add("clear", 0x0C);
            keycodedic.Add("enter", 0x0D);
            keycodedic.Add("SHIFT", 0x10);
            keycodedic.Add("CTRL", 0x11);
            keycodedic.Add("ALT", 0x12);
            keycodedic.Add("pause", 0x13);
            keycodedic.Add("caps_lock", 0x14);
            keycodedic.Add("esc", 0x1B);
            keycodedic.Add("spacebar", 0x20);
            keycodedic.Add("page_up", 0x21);
            keycodedic.Add("page_down", 0x22);
            keycodedic.Add("end", 0x23);
            keycodedic.Add("home", 0x24);
            keycodedic.Add("LEFT", 0x25);
            keycodedic.Add("up_arrow", 0x26);
            keycodedic.Add("RIGHT", 0x27);
            keycodedic.Add("DOWN", 0x28);
            keycodedic.Add("select", 0x29);
            keycodedic.Add("print", 0x2A);
            keycodedic.Add("execute", 0x2B);
            keycodedic.Add("print_screen", 0x2C);
            keycodedic.Add("ins", 0x2D);
            keycodedic.Add("del", 0x2E);
            keycodedic.Add("help", 0x2F);
            keycodedic.Add("0", 0x30);
            keycodedic.Add("1", 0x31);
            keycodedic.Add("2", 0x32);
            keycodedic.Add("3", 0x33);
            keycodedic.Add("4", 0x34);
            keycodedic.Add("5", 0x35);
            keycodedic.Add("6", 0x36);
            keycodedic.Add("7", 0x37);
            keycodedic.Add("8", 0x38);
            keycodedic.Add("9", 0x39);
            keycodedic.Add("a", 0x41);
            keycodedic.Add("b", 0x42);
            keycodedic.Add("c", 0x43);
            keycodedic.Add("d", 0x44);
            keycodedic.Add("e", 0x45);
            keycodedic.Add("f", 0x46);
            keycodedic.Add("g", 0x47);
            keycodedic.Add("h", 0x48);
            keycodedic.Add("i", 0x49);
            keycodedic.Add("j", 0x4A);
            keycodedic.Add("k", 0x4B);
            keycodedic.Add("l", 0x4C);
            keycodedic.Add("m", 0x4D);
            keycodedic.Add("n", 0x4E);
            keycodedic.Add("o", 0x4F);
            keycodedic.Add("p", 0x50);
            keycodedic.Add("q", 0x51);
            keycodedic.Add("r", 0x52);
            keycodedic.Add("s", 0x53);
            keycodedic.Add("t", 0x54);
            keycodedic.Add("u", 0x55);
            keycodedic.Add("v", 0x56);
            keycodedic.Add("w", 0x57);
            keycodedic.Add("x", 0x58);
            keycodedic.Add("y", 0x59);
            keycodedic.Add("z", 0x5A);
            keycodedic.Add("numpad_0", 0x60);
            keycodedic.Add("numpad_1", 0x61);
            keycodedic.Add("numpad_2", 0x62);
            keycodedic.Add("numpad_3", 0x63);
            keycodedic.Add("numpad_4", 0x64);
            keycodedic.Add("numpad_5", 0x65);
            keycodedic.Add("numpad_6", 0x66);
            keycodedic.Add("numpad_7", 0x67);
            keycodedic.Add("numpad_8", 0x68);
            keycodedic.Add("numpad_9", 0x69);
            keycodedic.Add("multiply_key", 0x6A);
            keycodedic.Add("add_key", 0x6B);
            keycodedic.Add("separator_key", 0x6C);
            keycodedic.Add("subtract_key", 0x6D);
            keycodedic.Add("decimal_key", 0x6E);
            keycodedic.Add("divide_key", 0x6F);
            keycodedic.Add("F1", 0x70);
            keycodedic.Add("F2", 0x71);
            keycodedic.Add("F3", 0x72);
            keycodedic.Add("F4", 0x73);
            keycodedic.Add("F5", 0x74);
            keycodedic.Add("F6", 0x75);
            keycodedic.Add("F7", 0x76);
            keycodedic.Add("F8", 0x77);
            keycodedic.Add("F9", 0x78);
            keycodedic.Add("F10", 0x79);
            keycodedic.Add("F11", 0x7A);
            keycodedic.Add("F12", 0x7B);
            keycodedic.Add("F13", 0x7C);
            keycodedic.Add("F14", 0x7D);
            keycodedic.Add("F15", 0x7E);
            keycodedic.Add("F16", 0x7F);
            keycodedic.Add("F17", 0x80);
            keycodedic.Add("F18", 0x81);
            keycodedic.Add("F19", 0x82);
            keycodedic.Add("F20", 0x83);
            keycodedic.Add("F21", 0x84);
            keycodedic.Add("F22", 0x85);
            keycodedic.Add("F23", 0x86);
            keycodedic.Add("F24", 0x87);
            keycodedic.Add("num_lock", 0x90);
            keycodedic.Add("scroll_lock", 0x91);
            keycodedic.Add("left_shift", 0xA0);
            keycodedic.Add("right_shift ", 0xA1);
            keycodedic.Add("left_control", 0xA2);
            keycodedic.Add("right_control", 0xA3);
            keycodedic.Add("left_menu", 0xA4);
            keycodedic.Add("right_menu", 0xA5);
            keycodedic.Add("browser_back", 0xA6);
            keycodedic.Add("browser_forward", 0xA7);
            keycodedic.Add("browser_refresh", 0xA8);
            keycodedic.Add("browser_stop", 0xA9);
            keycodedic.Add("browser_search", 0xAA);
            keycodedic.Add("browser_favorites", 0xAB);
            keycodedic.Add("browser_start_and_home", 0xAC);
            keycodedic.Add("volume_mute", 0xAD);
            keycodedic.Add("volume_Down", 0xAE);
            keycodedic.Add("volume_up", 0xAF);
            keycodedic.Add("next_track", 0xB0);
            keycodedic.Add("previous_track", 0xB1);
            keycodedic.Add("stop_media", 0xB2);
            keycodedic.Add("play/pause_media", 0xB3);
            keycodedic.Add("start_mail", 0xB4);
            keycodedic.Add("select_media", 0xB5);
            keycodedic.Add("start_application_1", 0xB6);
            keycodedic.Add("start_application_2", 0xB7);
            keycodedic.Add("attn_key", 0xF6);
            keycodedic.Add("crsel_key", 0xF7);
            keycodedic.Add("exsel_key", 0xF8);
            keycodedic.Add("play_key", 0xFA);
            keycodedic.Add("zoom_key", 0xFB);
            keycodedic.Add("clear_key", 0xFE);
            keycodedic.Add("+", 0xBB);
            keycodedic.Add(",", 0xBC);
            keycodedic.Add("-", 0xBD);
            keycodedic.Add(".", 0xBE);
            keycodedic.Add("/", 0xBF);
            keycodedic.Add("`", 0xC0);
            keycodedic.Add(";", 0xBA);
            keycodedic.Add("[", 0xDB);
            keycodedic.Add("\\", 0xDC);
            keycodedic.Add("]", 0xDD);
            keycodedic.Add("'", 0xDE);
        }


    }
}
